import React, { Component } from 'react';
import {
    HashRouter as Router,
    Route,
    Link
} from 'react-router-dom';

import { setHtmlSize } from './utils/adaptive.js';

import checkManagement from './routes/pages/checkManagement';
import Page1 from './routes/pages/Page1';
import addManagerunPage from './routes/pages/add/addManagerunPage';
import  TitleCompoment from './components/TitleCompoment'

export default class BasicRoute extends Component {
    constructor(props) {
        super(props);
        this.state = {
            isPc:true
        };

        //自适应
        window.om = {
            //页面单位
            unit: "vh",
            viewWidth: (document.documentElement.clientWidth) * 0.01,
            viewHeight: (document.documentElement.clientHeight) * 0.01
        }
        setHtmlSize();
    }
    componentDidMount() {
        this.isPcFun();
        setHtmlSize()
    }
    componentWillUnmount() {
        window.removeEventListener("onorientationchange" in window ? "orientationchange" : "resize", () => { })
    }

    isPcFun = () =>{
        if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
            this.setState({
                isPc:false
            })
        } else {
            this.setState({
                isPc:true
            })
        }
    }
    render() {
        const { isPc } = this.state;
        return (
            
            <Router>
                <div className="contain" >
                    <TitleCompoment/>
                    <Route exact path="/" component={  isPc === true ? Page1 : checkManagement} />
                    <Route exact path="/result" component={checkManagement} />
                    <Route exact path="/resultall" component={checkManagement} />
                        <Route exact path="/add" component={  addManagerunPage } />
                </div>
            </Router>
        )
    }

}


